<?php
namespace app\admin\controller;

use think\Db;

class Log extends Base
{
	public function log()
	{
        if ($this->request->isPost() && $this->request->isAjax()) {
            // 查询
            $map = [];

            // 分页
            $page = $this->request->param('page/d', 0);
            $limit = $this->request->param('limit/d', 0);
            $count = Db::table('log')->where($map)->count();
    
            $data = Db::table('log')->where($map)->limit($limit * ($page - 1), $limit)->order('login_time desc')->select();

            // 返回数据
            $res = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $data,
            ];

            return json($res);
        }

		return $this->fetch();
	}

    public function logClear()
    {
        if ($this->request->isPost() && $this->request->isAjax()) {
            if (!Db::table('log')->delete(true)) {
                $this->result('', 1, '清除日志失败');
            }

            $this->result('', 0, '清除日志成功');
        }
    }
}
